package com.kitty.game.task.service.targetHandler;


import com.kitty.common.utils.SpringUtils;
import com.kitty.game.config.TaskSet;
import com.kitty.game.role.model.Role;
import com.kitty.game.task.model.product.TaskTarget;
import com.kitty.game.task.model.product.TaskTargetType;
import com.kitty.game.task.service.NewTaskService;
import com.kitty.listener.BaseGameEvent;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import java.util.List;

/** 押镖任务目标处理类*/
public class YaBiaoTargetHandler extends TaskTargetHandler {
    Logger logger = LoggerFactory.getLogger(getClass());

    @Override
    public void handleEvent(Role role, BaseGameEvent baseGameEvent) {

        logger.error("YaBiaoTargetHandler-------");
        /**处理召唤守护*/
        NewTaskService taskService = SpringUtils.getBean(NewTaskService.class);
        List<TaskSet> taskSetList = taskService.getAcceptedTasksMatchTarget(role, TaskTargetType.START_YA_BIAO);
        logger.error("taskSetList.size--{}",taskSetList.size());
        /**没有正在进行的守护任务*/
        if (taskSetList.size() == 0) {return ;}

        for (TaskSet taskSet : taskSetList) {
            TaskTarget roleDoingTaskTarget = taskService.getRoleDoingTaskTarget(role, taskSet);

            /**找不到正在进行任务目标时，跳过*/
            if (roleDoingTaskTarget == null) {continue;}

            taskService.updateTargetProgress(role, taskSet, roleDoingTaskTarget);
        }
    }

    @Override
    public void triggerNow(Role role, TaskSet taskSet, TaskTarget taskTarget) {
        logger.error("YaBiaoTargetHandler------triggerNow-");
    }
}
